package ${packageName}<#if moduleName??>.${moduleName}</#if>.controller<#if subModuleName??>.${subModuleName}</#if>;

import lombok.AllArgsConstructor;
import com.jk.global.model.result.ApiResult;
import com.jk.global.model.result.PageResult;
import org.springframework.beans.BeanUtils;
import ${packageName}<#if moduleName??>.${moduleName}</#if>.entity<#if subModuleName??>.${subModuleName}</#if>.${ClassName};
import ${packageName}<#if moduleName??>.${moduleName}</#if>.service<#if subModuleName??>.${subModuleName}</#if>.${ClassName}Service;
import ${packageName}<#if moduleName??>.${moduleName}</#if>.model.request.${ClassName}Query;
import ${packageName}<#if moduleName??>.${moduleName}</#if>.model.${ClassName}VO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* ${tableComment}
*
* @author ${author} ${email}
* @since ${version} ${date}
*/
@RestController
@RequestMapping("<#if moduleName??>${moduleName}/</#if>${classname}")
@AllArgsConstructor
public class ${ClassName}Controller {
    private final ${ClassName}Service ${className}Service;

    @GetMapping("queryPage")
    @PreAuthorize("hasAuthority('<#if moduleName??>${moduleName}:</#if>${classname}:page')")
    public ApiResult<PageResult<${ClassName}VO>> page(@RequestBody ${ClassName}Query query){
        PageResult<${ClassName}VO> page = ${className}Service.queryPage(query);
        return ApiResult.success(page);
    }

    @GetMapping("{id}")
    @PreAuthorize("hasAuthority('<#if moduleName??>${moduleName}:</#if>${classname}:info')")
    public ApiResult<${ClassName}VO> detail(@PathVariable("id") Long id){
        ${ClassName} entity = ${className}Service.query${ClassName}ById(id);
        ${ClassName}VO vo = new ${ClassName}VO();
        BeanUtils.copyProperties(vo,entity);
        return ApiResult.success(vo);
    }

    @PostMapping("insert")
    @PreAuthorize("hasAuthority('<#if moduleName??>${moduleName}:</#if>${classname}:save')")
    public ApiResult<String> insert(@RequestBody ${ClassName}VO vo){
        ${className}Service.insert(vo);
        return ApiResult.success(null);
    }

    @PostMapping("update")
    @PreAuthorize("hasAuthority('<#if moduleName??>${moduleName}:</#if>${classname}:update')")
    public ApiResult<String> update(@RequestBody  ${ClassName}VO vo){
        ${className}Service.update(vo);
        return ApiResult.success(null);
    }

    @PostMapping("delete")
    @PreAuthorize("hasAuthority('<#if moduleName??>${moduleName}:</#if>${classname}:delete')")
    public ApiResult<String> delete(@RequestBody List<Long> idList){
        ${className}Service.delete(idList);
        return ApiResult.success(null);
    }
}